<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>异步加载地图</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge">
    <style>
        body,
        html,
        #container {
            overflow: hidden;
            width: 100%;
            height: 100%;
            margin: 0;
            font-family: "微软雅黑";
        }
    </style>
    <script src="js/axios-0.18.0.js"></script>
    <script src="js/vuejs-2.5.16.js"></script>
    <script src="//api.map.baidu.com/api?type=webgl&v=1.0&ak=Gzym7Eqff6BswOD9iVwuSXX2jmOIgOu3"></script>
</head>
<body>
<div id="container"></div>
</body>
</html>
<script>
    function loadJScript() {
        var script = document.createElement('script');
        script.type = 'text/javascript';
        script.src = '//api.map.baidu.com/api?type=webgl&v=1.0&ak=Gzym7Eqff6BswOD9iVwuSXX2jmOIgOu3&callback=init';
        document.body.appendChild(script);
    }
    const loa = new Vue({
        el: '#container',
        data:{
            userLocation: {
                address:'',
                x: '',
                y: '',
            },
            userId: ''
        },
        methods:{
            getUserLocation(userId){
                axios.get("http://localhost:18088/houtai/user/location?userId="+userId,{
                    headers:{
                        Authorization:localStorage.getItem("Authorization")
                    }
                }).then(resp=>{
                    this.userLocation = resp.data; // 创建Map实例
                    console.log(this.userLocation);
                    var map = new BMapGL.Map('container'); // 创建Map实例
                    var point = new BMapGL.Point(this.userLocation.x,this.userLocation.y); // 创建点坐标
                    map.centerAndZoom(point, 18);
                    map.enableScrollWheelZoom(true); // 启用滚轮放大缩小
                    var marker1 = new BMapGL.Marker(new BMapGL.Point(this.userLocation.x, this.userLocation.y));//创建点标记
                    map.addOverlay(marker1);
                })
            }
        },
        created(){
            this.userId = window.location.href.split('=')[1];
            this.getUserLocation(this.userId);
        }
    });

    window.onload = loadJScript; // 异步加载地图
</script>